<template>
  <div class="result_item">
    <div class="top">
      <div class="image">
        <el-avatar :src="item.avatar" shape="square"></el-avatar>
      </div>
      <div class="info">
        <div class="left">
          <span class="name"
            >昵称:
            {{ item.username }}
          </span>
          <span class="sign"
            >签名:{{ item.sign ? item.sign : '暂无签名' }}</span
          >
        </div>
        <div class="right">
          <span v-if="item.email" class="email">邮箱:{{ item.email }}</span>
          <span v-if="item.area" class="area">地区: {{ item.area }}</span>
        </div>
      </div>
    </div>
    <div class="bottom">
      <div v-if="item.isFriend">
        <el-button type="primary" @click="sendMessage">发消息</el-button>
        <el-button type="success" @click="lookInfo">查看信息</el-button>
        <el-button type="danger" @click="deleteFriend">删除好友</el-button>
      </div>
      <div v-else>
        <el-button type="primary" @click="addFriend">添加好友</el-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
defineProps({
  item: {
    type: Object,
    default: () => {}
  }
})

const emit = defineEmits([
  'sendMessage',
  'lookInfo',
  'addFriend',
  'deleteFriend'
])

const sendMessage = () => {
  console.log('发送消息')
  emit('sendMessage')
}

const lookInfo = () => {
  console.log('查看信息')
  emit('lookInfo')
}

const addFriend = () => {
  console.log('添加好友')
  emit('addFriend')
}

const deleteFriend = () => {
  console.log('删除好友')
  emit('deleteFriend')
}
</script>

<style lang="scss" scoped>
.result_item {
  width: 350px;
  margin-bottom: 25px;
  /* background-color: red; */
  .top {
    display: flex;
    align-items: center;
    .info {
      /* flex: 1; */
      font-size: 14px;
      display: flex;
      justify-content: space-between;
      margin-left: 15px;
      /* background-color: red; */
      .left {
        /* flex: 1; */
        width: 175px;
        display: flex;
        flex-direction: column;
        flex-shrink: 0;
        .name {
          margin-bottom: 10px;
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
          margin-bottom: 10px;
        }
        .sign {
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
          margin-bottom: 10px;
        }
      }

      .right {
        width: 175px;
        display: flex;
        flex-direction: column;
        flex-shrink: 1;
        .email {
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
          margin-bottom: 10px;
        }
      }
    }
  }

  .bottom {
    display: flex;
    justify-content: center;
    margin-top: 20px;
  }
}
</style>
